#include "task_app.h"



void TouchTask(void) {
    static TouchInfo_t touchInfo;
    TouchScan(&touchInfo);
    if(touchInfo.state) {
			printf("touch x:%d,y:%d,size:%d\r\n",touchInfo.point.x,touchInfo.point.y,touchInfo.point.size);
    }
}

/**
 * @desc  : 按键任务
 * @date  : 2025-04-22
 * @author: AnRui
 * @note  :
 */
void KeyTask(void) {
    uint8_t code = GetKeyStatusCode();
    SysParam_t tmp;
    // 短按
    switch (code) {
    case KEY1_SHORT_STATUS_CODE:
        //        if (!UpdateSysParamModbusAddr(0x22)) {
        //            printf("UpdateSysParamModbusAddr error");
        //            return;
        //        }
        // tmp = GetSysParam();
        // printf("ModbusAddr:%02x\n", tmp.modbusAddr);
        PrintSensorFile();
        break;
    case KEY2_SHORT_STATUS_CODE:
        if (!UpdateSysParamModbusAddr(0x44)) {
            printf("UpdateSysParamModbusAddr error");
            return;
        }
        tmp = GetSysParam();
        printf("ModbusAddr:%02x\n", tmp.modbusAddr);
        break;
    default:
        break;
    }


}





/**
 * @desc  : ADC任务
 * @date  : 2025-04-07
 * @author: AnRui
 * @note  :
 */
void AdcTask(void) {
    uint16_t buf[10] = { 0 };
    uint16_t* adc_arr = GetADC0RoutineChannelResultArrPointer();
    memcpy(buf, adc_arr, sizeof(uint16_t) * 10);
    for (uint8_t i = 0; i < 10; i++) {
        printf("AdcVal[%d] = %d.\n", i, buf[i]);
    }
    // adc 软件滤波算法 计算10次adc采样的算术平均值
    uint16_t res = MathCalcArithmeticMean(buf, 10);

    printf("res = %d.\n", res);


}

/**
 * @desc  : RTC测试任务
 * @date  : 2025-04-07
 * @author: AnRui
 * @note  :
 */
void RtcTask() {
    RtcTime_t rtcTime;
    GetRtcTime(&rtcTime);
    printf("%04d-%02d-%02d %02d:%02d:%02d\n",
           rtcTime.year, rtcTime.month, rtcTime.day,
           rtcTime.hour, rtcTime.minute, rtcTime.second);
}


/**
 * @desc  : 独立看门狗喂狗任务
 * @date  : 2025-04-07
 * @author: AnRui
 * @note  :
 */
void FwdgtTask(void) {
    FWDGT_feed();
}


/**
 * @desc  : 窗口看门狗喂狗任务
 * @date  : 2025-04-07
 * @author: AnRui
 * @note  :
 */
void WwdgtTask(void) {
    WWDGT_feed();
}


/**
 * @desc  : 温度传感器测试任务
 * @date  : 2025-04-09
 * @author: AnRui
 * @note  :
 */
void SensorProcTask(void) {
    SensorDrvProc();
}

/**
 * @desc  : 温度传感器结果任务
 * @date  : 2025-04-09
 * @author: AnRui
 * @note  :
 */
void SensorResultTask(void) {
    SensorData_t sensorData;
    GetSensorData(&sensorData);
    printf("\n temp %.2f, humi %d \n", sensorData.temp, sensorData.humi);
}










